package com.ai.multimodel.controller;

import org.springframework.ai.chat.messages.Media;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.MimeTypeUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.net.URL;
import java.util.List;

@RestController
public class MultiModelController {

    @Autowired
    private OpenAiChatModel chatModel;

    @RequestMapping(value = "/ai/multi")
    public Object multi(String msg, String imageUrl) throws IOException {
        var userMessage = new UserMessage(
                "Explain what do you see in this picture?", // content
                List.of(new Media(MimeTypeUtils.IMAGE_PNG, new URL(imageUrl)))); // media

        ChatResponse response = chatModel.call(new Prompt(List.of(userMessage)));
        return response;
    }


}

